<?php

namespace App\Http\Controllers\Admin;

use App\Model\BasePicture;
use App\Model\Secify;
use App\Model\Spot;
use App\Model\Sreason;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class NotSpotController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $page = Spot::where('state',0)->paginate(15);
        $data = Spot::where('state',0)->orderBy('id','desc')->paginate(15);
        foreach ($data as $key => $value){
            $items[] = BasePicture::where('spot_id',$value->id)->first();
        }
        $secify = Secify::get();
        return view('admin.place.place-not-spot-list',compact('data','secify','page','items'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $val = $request->input('data');
        $hid = $request->input('sid');
        $data = Sreason::create(['sid'=>$hid,'reason'=>$val]);
        if ($data){
            return $this->success('提交成功');
        }else {
            return $this->error('提交失败');
        }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
//        $item = Spot::where('id',$id)->first();
//        $secify = Secify::get();
//        return view('admin.place.place-not-spot-show',compact('item','secify'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $item = Spot::where('id',$id)->first();
        $secify = Secify::get();
        return view('admin.place.place-spot-not-show',compact('item','secify'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $m = Spot::find($id);
        $m->state = 1;
        if ($m->save()){
            return $this->success('操作成功');
        }else {
            return $this->error('操作失败');
        }
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
